package o;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import com.huawei.hms.framework.common.ContainerUtils;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.WeakHashMap;

@RestrictTo({androidx.annotation.RestrictTo.d.ॱ})
public class dh<K, V> implements Iterable<Entry<K, V>> {
    private WeakHashMap<i<K, V>, Boolean> ˊ = new WeakHashMap();
    d<K, V> ˋ;
    private int ˎ = 0;
    private d<K, V> ˏ;

    interface i<K, V> {
        void ˎ(@NonNull d<K, V> dVar);
    }

    static abstract class c<K, V> implements Iterator<Entry<K, V>>, i<K, V> {
        d<K, V> ˏ;
        d<K, V> ॱ;

        abstract d<K, V> ˋ(d<K, V> dVar);

        abstract d<K, V> ॱ(d<K, V> dVar);

        public /* synthetic */ Object next() {
            return ˎ();
        }

        c(d<K, V> dVar, d<K, V> dVar2) {
            this.ˏ = dVar2;
            this.ॱ = dVar;
        }

        public boolean hasNext() {
            return this.ॱ != null;
        }

        public void ˎ(@NonNull d<K, V> dVar) {
            if (this.ˏ == dVar && dVar == this.ॱ) {
                this.ॱ = null;
                this.ˏ = null;
            }
            if (this.ˏ == dVar) {
                this.ˏ = ˋ(this.ˏ);
            }
            if (this.ॱ == dVar) {
                this.ॱ = ˋ();
            }
        }

        private d<K, V> ˋ() {
            if (this.ॱ == this.ˏ || this.ˏ == null) {
                return null;
            }
            return ॱ(this.ॱ);
        }

        public Entry<K, V> ˎ() {
            Entry entry = this.ॱ;
            this.ॱ = ˋ();
            return entry;
        }
    }

    static class a<K, V> extends c<K, V> {
        a(d<K, V> dVar, d<K, V> dVar2) {
            super(dVar, dVar2);
        }

        d<K, V> ॱ(d<K, V> dVar) {
            return dVar.ˎ;
        }

        d<K, V> ˋ(d<K, V> dVar) {
            return dVar.ˋ;
        }
    }

    static class b<K, V> extends c<K, V> {
        b(d<K, V> dVar, d<K, V> dVar2) {
            super(dVar, dVar2);
        }

        d<K, V> ॱ(d<K, V> dVar) {
            return dVar.ˋ;
        }

        d<K, V> ˋ(d<K, V> dVar) {
            return dVar.ˎ;
        }
    }

    static class d<K, V> implements Entry<K, V> {
        @NonNull
        final K ˊ;
        d<K, V> ˋ;
        d<K, V> ˎ;
        @NonNull
        final V ॱ;

        d(@NonNull K k, @NonNull V v) {
            this.ˊ = k;
            this.ॱ = v;
        }

        @NonNull
        public K getKey() {
            return this.ˊ;
        }

        @NonNull
        public V getValue() {
            return this.ॱ;
        }

        public V setValue(V v) {
            throw new UnsupportedOperationException("An entry modification is not supported");
        }

        public String toString() {
            return this.ˊ + ContainerUtils.KEY_VALUE_DELIMITER + this.ॱ;
        }

        public boolean equals(Object obj) {
            if (obj == this) {
                return true;
            }
            if (!(obj instanceof d)) {
                return false;
            }
            d dVar = (d) obj;
            if (this.ˊ.equals(dVar.ˊ) && this.ॱ.equals(dVar.ॱ)) {
                return true;
            }
            return false;
        }

        public int hashCode() {
            return this.ˊ.hashCode() ^ this.ॱ.hashCode();
        }
    }

    public class e implements Iterator<Entry<K, V>>, i<K, V> {
        private d<K, V> ˋ;
        private boolean ˎ = true;
        final /* synthetic */ dh ॱ;

        public /* synthetic */ Object next() {
            return ˏ();
        }

        e(dh dhVar) {
            this.ॱ = dhVar;
        }

        public void ˎ(@NonNull d<K, V> dVar) {
            if (dVar == this.ˋ) {
                this.ˋ = this.ˋ.ˋ;
                this.ˎ = this.ˋ == null;
            }
        }

        public boolean hasNext() {
            if (this.ˎ) {
                if (this.ॱ.ˋ != null) {
                    return true;
                }
                return false;
            } else if (this.ˋ == null || this.ˋ.ˎ == null) {
                return false;
            } else {
                return true;
            }
        }

        public Entry<K, V> ˏ() {
            if (this.ˎ) {
                this.ˎ = false;
                this.ˋ = this.ॱ.ˋ;
            } else {
                this.ˋ = this.ˋ != null ? this.ˋ.ˎ : null;
            }
            return this.ˋ;
        }
    }

    protected d<K, V> ˎ(K k) {
        d<K, V> dVar = this.ˋ;
        while (dVar != null && !dVar.ˊ.equals(k)) {
            dVar = dVar.ˎ;
        }
        return dVar;
    }

    public V ˏ(@NonNull K k, @NonNull V v) {
        d ˎ = ˎ(k);
        if (ˎ != null) {
            return ˎ.ॱ;
        }
        ˋ(k, v);
        return null;
    }

    protected d<K, V> ˋ(@NonNull K k, @NonNull V v) {
        d<K, V> dVar = new d(k, v);
        this.ˎ++;
        if (this.ˏ == null) {
            this.ˋ = dVar;
            this.ˏ = this.ˋ;
        } else {
            this.ˏ.ˎ = dVar;
            dVar.ˋ = this.ˏ;
            this.ˏ = dVar;
        }
        return dVar;
    }

    public V ˊ(@NonNull K k) {
        d ˎ = ˎ(k);
        if (ˎ == null) {
            return null;
        }
        this.ˎ--;
        if (!this.ˊ.isEmpty()) {
            for (i ˎ2 : this.ˊ.keySet()) {
                ˎ2.ˎ(ˎ);
            }
        }
        if (ˎ.ˋ != null) {
            ˎ.ˋ.ˎ = ˎ.ˎ;
        } else {
            this.ˋ = ˎ.ˎ;
        }
        if (ˎ.ˎ != null) {
            ˎ.ˎ.ˋ = ˎ.ˋ;
        } else {
            this.ˏ = ˎ.ˋ;
        }
        ˎ.ˎ = null;
        ˎ.ˋ = null;
        return ˎ.ॱ;
    }

    public int ˏ() {
        return this.ˎ;
    }

    @NonNull
    public Iterator<Entry<K, V>> iterator() {
        Iterator aVar = new a(this.ˋ, this.ˏ);
        this.ˊ.put(aVar, Boolean.valueOf(false));
        return aVar;
    }

    public Iterator<Entry<K, V>> ॱ() {
        Iterator bVar = new b(this.ˏ, this.ˋ);
        this.ˊ.put(bVar, Boolean.valueOf(false));
        return bVar;
    }

    public e ˊ() {
        e eVar = new e(this);
        this.ˊ.put(eVar, Boolean.valueOf(false));
        return eVar;
    }

    public Entry<K, V> ˋ() {
        return this.ˋ;
    }

    public Entry<K, V> ˎ() {
        return this.ˏ;
    }

    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof dh)) {
            return false;
        }
        dh dhVar = (dh) obj;
        if (ˏ() != dhVar.ˏ()) {
            return false;
        }
        Iterator it = iterator();
        Iterator it2 = dhVar.iterator();
        while (it.hasNext() && it2.hasNext()) {
            Entry entry = (Entry) it.next();
            Object next = it2.next();
            if (entry == null && next != null) {
                return false;
            }
            if (entry != null && !entry.equals(next)) {
                return false;
            }
        }
        boolean z = (it.hasNext() || it2.hasNext()) ? false : true;
        return z;
    }

    public int hashCode() {
        Iterator it = iterator();
        int i = 0;
        while (it.hasNext()) {
            i = ((Entry) it.next()).hashCode() + i;
        }
        return i;
    }

    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("[");
        Iterator it = iterator();
        while (it.hasNext()) {
            stringBuilder.append(((Entry) it.next()).toString());
            if (it.hasNext()) {
                stringBuilder.append(", ");
            }
        }
        stringBuilder.append("]");
        return stringBuilder.toString();
    }
}
